<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./css/reset.css">
    <style>
        .section {
          width: 660px;
          min-height: 370px;
          background: #fff;
          margin: 0 auto;
          margin-top: 80px;
          overflow: hidden;
          display: flex;
          flex-direction: column;
          align-items: center;
        }
        img {
          display: block;
          width: 160px;
          height: 42px;
          margin: 0 auto;
          margin-top: 60px;
        }
        .title {
          width: 660px;
          height: 30px;
          font-family: HYQiHei-FZS;
          font-size: 22px;
          color: #000;
          text-align: center;
          margin-top: 40px;
        }
        .copyright{
            width: auto;
            margin-top: 100px;
            text-align: center;
            font-size: 10px;
        }
        .chec{
            font-size: 14px;
        }
        .ere{
          color: red;
          display: none;
        }
      </style>
      <script src="./php/ajax.js" type="text/javascript" charset="utf-8"></script>
      <script src="./php/cookie.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
    <div class="section">
        <img src="./img/1.png" alt="" />
        <div class="title">账号登入</div>
        <br />
        <div>姓名：<input type="text" class="username" name="username" /></div>
        <br />
        <div>密码：<input type="text" class="pwd" name="pwd" /></div>
        <p class="ere">姓名或密码输入错误</p>
        <br />
        <div class="chec">记住我<input type="checkbox" class="remeber">
            <input type="submit" class="login" value="立即登入" />
            <input type="submit" value="取消登入" class="center"></div>
        
      </div>
      <div class="copyright">
          COPYRIGHT ©2011-2021 广东天宸网络科技有限公司 版权所有 保留一切权利 | 隐私政策 | 法律声明 | 粤B2-20080267 | 粤ICP备05100288号 
      </div>
      <script>

let usernameEle = document.querySelector(".username");
let pwdEle = document.querySelector(".pwd");
let loginEle = document.querySelector(".login");
let remeberEle = document.querySelector(".remeber");
let ereEle = document.querySelector(".ere")

  loginEle.onclick = function(){
	  let username = usernameEle.value;
	  let pwd = pwdEle.value;
	  ajax({
		  url:"./php/centers.php",
		  method:"post",
		  data:{
			 username,
			  pwd
		  },
		  dataType:"json",
	  }).then(res=>{
		if(res.status==1){
				  console.log(res);
				  document.cookie = "username="+res.data.username;
				  document.cookie = "uid="+res.data.id;
				  if(remeberEle.checked){
					  setCookie("username",res.data.username,3600*24*7);
					  setCookie("uid",res.data.id,3600*24*7);
				  }
				  window.location.href = "index.html";
			  }else{
          ereEle.style.display="block";
        }
	  })
  }
  let centerEle = document.querySelector(".center");
        centerEle.onclick=function(){
          delCookie("username");
          delCookie("uid");
          window.location.href="index.html";
        }
      </script>
</body>
</html>